package com.ht.ui.actions.help;

import com.ht.aems.swing.util.MyAction;

import javax.help.CSH;
import javax.help.HelpBroker;
import javax.help.HelpSet;
import java.awt.event.ActionEvent;
import java.net.URL;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date: 2011-5-31
 */
public class Help extends MyAction {
    static CSH.DisplayHelpFromSource helpListener = null;

    static {
        HelpSet mainHS;
        HelpBroker mainHB;
        String helpsetName = "help/help";
        try {
            ClassLoader cl = Help.class.getClassLoader();
            URL url = HelpSet.findHelpSet(cl, helpsetName);
            mainHS = new HelpSet(cl, url);
            mainHB = mainHS.createHelpBroker();
            helpListener = new CSH.DisplayHelpFromSource(mainHB);
        } catch (Exception ee) {
            System.out.println("Help Set " + helpsetName + " not found");
        } catch (ExceptionInInitializerError ex) {
            System.err.println("initialization error:");
            ex.getException().printStackTrace();
        }
    }

    public void actionPerformed(ActionEvent e) {
        if (helpListener != null)
            helpListener.actionPerformed(e);
    }
}
